package com.usian.model.base;

import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.model.common.dtos.PageRequestDto;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;

public class BaseServiceImpl<M extends BaseMapper<T>,T> extends ServiceImpl<M,T> {
    public ResponseResult paramError=ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    public ResponseResult paramSuccess=ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    public ResponseResult paramDeleteFail=ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID,"频道删除失败");
    public ResponseResult paramCantDelete=ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID,"频道有效不能删除");
    public ResponseResult paramDeleteSuccess=ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID,"频道删除成功");
    public ResponseResult notExits=ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST, "用户不存在");
    public ResponseResult pwdError=ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID, "密码错误");
    public ResponseResult needLogin=ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN);
    public ResponseResult getPageResult(PageRequestDto dto, IPage page, AbstractWrapper wrapper) {
        IPage pageResult = page(page, wrapper);
        ResponseResult result = new PageResponseResult(dto.getPage(), dto.getSize(), (int) pageResult.getTotal());
        result.setData(pageResult.getRecords());
        return result;
    }
    public ResponseResult getPageResult(PageRequestDto dto,AbstractWrapper wrapper) {
        Page page = new Page();
        IPage pageResult = page(page, wrapper);
        ResponseResult result = new PageResponseResult(dto.getPage(), dto.getSize(), (int) pageResult.getTotal());
        result.setData(pageResult.getRecords());
        return result;
    }
}